
#ifndef ICONVEXCONCAVEALGORITHM_H
#define ICONVEXCONCAVEALGORITHM_H

#include "IAlgorithm.h"
#include "IBroadphase.h"
#include "ITriangleCallback.h"
#include "IOverlapPair.h"
#include "ITriangleShape.h"
#include "IConvexConvexAlgorithm.h"

namespace BWE
{
	class IConvexConcaveAlgorithm : public IAlgorithm
	{
	public:
		IConvexConcaveAlgorithm();
		~IConvexConcaveAlgorithm();

		virtual void caculate() override;
		virtual void timeImpact() override;

	private:
		class ConvexTriangleCallback : public ITriangleCallback
		{
		public:
			ITriangleShape		triangleShape;
			BHolder<IAlgorithm>	algorithm;

		public:
			void setup(BReal margin,
				BBody* convexBody, BShape* convexShape, const BMatrix& convexTransform,
				BBody* concaveBody, BShape* concaveShape, const BMatrix& concaveTransform)
			{
				triangleShape.setMargin(margin);
				algorithm = new IConvexConvexAlgorithm();
				algorithm->setBodyA(convexBody, convexShape, convexTransform);
				algorithm->setBodyB(concaveBody, &triangleShape, concaveTransform);
				algorithm->setBodyA(convexBody, convexShape, convexTransform);
				algorithm->setBodyB(concaveBody, &triangleShape, concaveTransform);
			}

			virtual void process(const BTriangle& triangle, int triangleIndex)
			{
				triangleShape.setTriangle(triangle);
				algorithm->caculate();
			}

		};

		ConvexTriangleCallback _callback;
	};
}
#endif
